<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <img src="/non-existing-image.png"/>
  <div></div>
  <script>
    const img = document.querySelector('img')
    const div = document.querySelector('div')

    img.onload = () => {
      div.innerHTML = 'it loaded'
    }

    img.onerror = () => {
      div.innerHTML = 'error loading image'
    }
  </script>
</body>
</html>
